Socket
Socket
Sign inDemoInstall

@improbable-eng/grpc-web

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@improbable-eng/grpc-web

gRPC-Web client for browsers (JS/TS)


Version published
Weekly downloads
125K
decreased by-21.46%
Maintainers
2
Weekly downloads
 
Created

What is @improbable-eng/grpc-web?

@improbable-eng/grpc-web is a JavaScript library that allows you to use gRPC in web applications. It provides a way to communicate with gRPC services from the browser using HTTP/1.1 or HTTP/2, enabling real-time communication and efficient data transfer.

What are @improbable-eng/grpc-web's main functionalities?

Unary RPC

This feature allows you to make a unary RPC call to a gRPC service. The code sample demonstrates how to create a request, set its parameters, and send it to the server. The response is handled in the onEnd callback.

const {grpc} = require('@improbable-eng/grpc-web');
const {MyService} = require('./my_service_pb_service');
const {MyRequest} = require('./my_service_pb');

const request = new MyRequest();
request.setMessage('Hello, World!');

grpc.unary(MyService.MyMethod, {
  request: request,
  host: 'http://localhost:8080',
  onEnd: (response) => {
    const {status, message} = response;
    if (status === grpc.Code.OK && message) {
      console.log('Response:', message.toObject());
    }
  }
});

Server Streaming RPC

This feature allows you to make a server streaming RPC call to a gRPC service. The code sample demonstrates how to create a request, set its parameters, and handle incoming messages from the server in real-time.

const {grpc} = require('@improbable-eng/grpc-web');
const {MyService} = require('./my_service_pb_service');
const {MyRequest} = require('./my_service_pb');

const request = new MyRequest();
request.setMessage('Hello, World!');

const stream = grpc.invoke(MyService.MyStreamingMethod, {
  request: request,
  host: 'http://localhost:8080',
  onMessage: (message) => {
    console.log('Received message:', message.toObject());
  },
  onEnd: (status, statusMessage, trailers) => {
    if (status === grpc.Code.OK) {
      console.log('Stream ended successfully');
    } else {
      console.error('Stream ended with error:', statusMessage);
    }
  }
});

Client Streaming RPC

This feature allows you to make a client streaming RPC call to a gRPC service. The code sample demonstrates how to create a stream, send multiple requests, and handle the end of the stream.

const {grpc} = require('@improbable-eng/grpc-web');
const {MyService} = require('./my_service_pb_service');
const {MyRequest} = require('./my_service_pb');

const stream = grpc.client(MyService.MyClientStreamingMethod, {
  host: 'http://localhost:8080'
});

stream.onEnd((status, statusMessage, trailers) => {
  if (status === grpc.Code.OK) {
    console.log('Stream ended successfully');
  } else {
    console.error('Stream ended with error:', statusMessage);
  }
});

const request1 = new MyRequest();
request1.setMessage('Message 1');
stream.send(request1);

const request2 = new MyRequest();
request2.setMessage('Message 2');
stream.send(request2);

stream.finishSend();

Bidirectional Streaming RPC

This feature allows you to make a bidirectional streaming RPC call to a gRPC service. The code sample demonstrates how to create a stream, send multiple requests, and handle incoming messages from the server in real-time.

const {grpc} = require('@improbable-eng/grpc-web');
const {MyService} = require('./my_service_pb_service');
const {MyRequest} = require('./my_service_pb');

const stream = grpc.client(MyService.MyBidirectionalStreamingMethod, {
  host: 'http://localhost:8080'
});

stream.onMessage((message) => {
  console.log('Received message:', message.toObject());
});

stream.onEnd((status, statusMessage, trailers) => {
  if (status === grpc.Code.OK) {
    console.log('Stream ended successfully');
  } else {
    console.error('Stream ended with error:', statusMessage);
  }
});

const request1 = new MyRequest();
request1.setMessage('Message 1');
stream.send(request1);

const request2 = new MyRequest();
request2.setMessage('Message 2');
stream.send(request2);

stream.finishSend();

Other packages similar to @improbable-eng/grpc-web

Keywords

FAQs

Package last updated on 04 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc